﻿using System;


namespace DevMaker.SIC.Model.BaseObject {
    public abstract class IdentifiableObject : IComparable {
        public virtual long Id { get; set; }

        public virtual void Initialize() {

        }

        public virtual bool IsNew {
            get { return Id == 0; }
        }

        public virtual string GetUniqueCode() {
            return Id.ToString();
        }


        #region IComparable Members

        public virtual int CompareTo(object obj) {
            var reference = obj as IdentifiableObject;
            return reference == null ? 1 : Id.CompareTo(reference.Id);
        }

        public override bool Equals(object obj) {
            var reference = obj as IdentifiableObject;
            if (reference == null) {
                return false;
            }

            if (Id.Equals(0) && reference.Id.Equals(0)) {
                return ReferenceEquals(this, reference);
            }
            return CompareTo(obj).Equals(0);
        }

        #endregion

    }
}
